home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Circular fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  3.7 KB  |  135 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Circular fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 2
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short CircularFade(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* Trace a region from the center to the topleft corner, over <BlockSize> pixels,
  38.    and back to the center.  Fill that in and move the region parameters +BlockSize.
  39.    Repeat for all sides. */
  40.  
  41. pascal short CircularFade(Rect boundsRect, Pattern *thePattern)
  42. {
  43.     RgnHandle    curregion;
  44.     int            cx,cy,lastx,lasty;
  45.     int            BlockSize;
  46.     RgnHandle    boundsRgn,sectrgn;
  47.     
  48.     BlockSize=theWindowWidth/40;
  49.     cx = boundsRect.left + theWindowWidth / 2;
  50.     cy = boundsRect.top + theWindowHeight / 2;
  51.  
  52.     boundsRgn=NewRgn();
  53.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  54.     
  55.     sectrgn=NewRgn();
  56.     curregion=NewRgn();
  57.     lastx=boundsRect.left;
  58.     do                                            /* top quadrant */
  59.     {
  60.         StartTiming();
  61.         SetEmptyRgn(curregion);
  62.         MoveTo(cx,cy);
  63.         OpenRgn();
  64.             LineTo(lastx,boundsRect.top);
  65.             Line(BlockSize,0);
  66.             LineTo(cx,cy);
  67.         CloseRgn(curregion);
  68.         SectRgn(boundsRgn, curregion, sectrgn);
  69.         FillRgn(sectrgn, *thePattern);
  70.         lastx+=BlockSize;
  71.         TimeCorrection(CorrectTime);
  72.     }
  73.     while (lastx<boundsRect.right);
  74.     
  75.     lasty=boundsRect.top;
  76.     do                                            /* right quadrant */
  77.     {
  78.         StartTiming();
  79.         SetEmptyRgn(curregion);
  80.         MoveTo(cx,cy);
  81.         OpenRgn();
  82.             LineTo(boundsRect.right,lasty);
  83.             Line(0,BlockSize);
  84.             LineTo(cx,cy);
  85.         CloseRgn(curregion);
  86.         SectRgn(boundsRgn, curregion, sectrgn);
  87.         FillRgn(sectrgn, *thePattern);
  88.         lasty+=BlockSize;
  89.         TimeCorrection(CorrectTime);
  90.     }
  91.     while (lasty<boundsRect.bottom);
  92.     
  93.     lastx=boundsRect.right;
  94.     do                                            /* bottom quadrant */
  95.     {
  96.         StartTiming();
  97.         SetEmptyRgn(curregion);
  98.         MoveTo(cx,cy);
  99.         OpenRgn();
  100.             LineTo(lastx,boundsRect.bottom);
  101.             Line(-BlockSize, 0);
  102.             LineTo(cx,cy);
  103.         CloseRgn(curregion);
  104.         SectRgn(boundsRgn, curregion, sectrgn);
  105.         FillRgn(sectrgn, *thePattern);
  106.         lastx-=BlockSize;
  107.         TimeCorrection(CorrectTime);
  108.     }
  109.     while (lastx>boundsRect.left-BlockSize);
  110.     
  111.     lasty=boundsRect.bottom;
  112.     do                                            /* left quadrant */
  113.     {
  114.         StartTiming();
  115.         SetEmptyRgn(curregion);
  116.         MoveTo(cx,cy);
  117.         OpenRgn();
  118.             LineTo(boundsRect.left,lasty);
  119.             Line(0, -BlockSize);
  120.             LineTo(cx,cy);
  121.         CloseRgn(curregion);
  122.         SectRgn(boundsRgn, curregion, sectrgn);
  123.         FillRgn(sectrgn, *thePattern);
  124.         lasty-=BlockSize;
  125.         TimeCorrection(CorrectTime);
  126.     }
  127.     while (lasty>boundsRect.top-BlockSize);
  128.     
  129.     DisposeRgn(curregion);
  130.     DisposeRgn(sectrgn);
  131.     DisposeRgn(boundsRgn);
  132.     
  133.     return 0;
  134. }
  135.